package com.attendance.chdingtask.controller;

import com.attendance.chdingtask.config.WebLog;
import com.attendance.chdingtask.model.CorpUserDetail;
import com.attendance.chdingtask.model.UserInfo;
import com.attendance.chdingtask.model.UserQryParm;
import com.attendance.chdingtask.service.UserInfoService;
import com.attendance.chdingtask.utils.common.Page;
import com.attendance.chdingtask.utils.common.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@Api(value = "user", description = "人员相关接口", consumes = "application/json;charset=UTF-8")
@RequestMapping("/user")
public class UserInfoController extends BaseController {


    @Autowired
    private UserInfoService userInfoService;

    @PostMapping("/findUserByData")
    @ResponseBody
    @WebLog(description = "员工列表查询")
    @ApiOperation(value = "员工列表查询，根据条件查询", notes = "{\"userId\": \"用户id\",\"limit\": \"分页大小，此参数代表分页大小，最大100\",\"offset\": \"分页偏移，默认值：0\",\"startDate\": \"开始时间\",\"endDate\": \"结束时间\",\"searchDate\": \"搜索\"}")
    public Result findUserByData(HttpServletRequest request, @RequestBody UserQryParm vo ) {
        Page<UserInfo> page =new Page<>();
        try {
//            CorpUserDetail user = getUserInfo(request);
//            if(null ==user ){
//                return Result.error("用户不可为空，请检查！");
//            }
//            checkNull(vo,"参数不可为空！");
            page.setPageCurrent(vo.getOffset()+1);
            page.setPageSize(vo.getLimit());
            userInfoService.findUserByData(vo,page,"dingfad484fb83b2303dffe93478753d9884");
//            checkNull(vo,"参数不可为空！");
//            page.setPageCurrent(vo.getOffset()+1);
//            page.setPageSize(vo.getLimit());
//            userInfoService.findUserByData(vo,page,null);

        }catch (Exception e){
            return Result.error(e.getMessage());
        }
        return Result.success(page);
    }
}
